package net.kelissa.divizor.jenetic;

import net.kelissa.divizor.model.DivizorModel;
import net.kelissa.divizor.util.Pair;
import net.kelissa.jenetic.Gene;
import net.kelissa.jenetic.RandomUtil;

public class DivizorValue
{

  private Pair<DivizorModel, DivizorModel> allele;

  public DivizorValue(DivizorModel one, DivizorModel two)
  {
    this.allele = new Pair<DivizorModel, DivizorModel>(one,two);
  }

  public void mutate()
  {
    double rand = RandomUtil.getRandom().nextDouble();
    if (rand < 0.5)
      this.allele.getOne().mutate();
    else
      this.allele.getTwo().mutate();
  }


  public DivizorValue conceive(DivizorValue value)
  {
    double rand = RandomUtil.getRandom().nextDouble();
    DivizorModel one;
    if (rand < 0.5)
      one = this.allele.getOne().clone();
    else
      one = this.allele.getTwo().clone();
    rand = RandomUtil.getRandom().nextDouble();
    DivizorModel two;
    if (rand < 0.5)
      two = value.getAllele().getOne().clone();
    else
      two = value.getAllele().getTwo().clone();
    return new DivizorValue(one, two);
  }

  public DivizorValue clone()
  {
    return new DivizorValue(this.allele.getOne().clone(), this.allele.getTwo().clone());
  }

  //----------------------------------
  public Pair<DivizorModel, DivizorModel> getAllele()
  {
    return allele;
  }

  public void setAllele(Pair<DivizorModel, DivizorModel> allele)
  {
    this.allele = allele;
  }

}
